<template>
  <el-dialog
    :close-on-click-modal="false"
    :show-close="false"
    title="退款审核"
    :visible.sync="isRefund"
  >
    <el-form
      :rules="rules"
      ref="ruleForm"
      :model="form"
      label-width="120px"
      size="small"
      class="form-box"
    >
      <el-form-item label="申请退款金额">
       <p>{{form.refund_expect}}</p>
      </el-form-item>
      
      <el-form-item label="是否通过" prop="status">
        <el-radio-group v-model="form.status">
          <el-radio :label="0">拒绝</el-radio>
          <el-radio :label="1">通过</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="form.status == 1" label="退款金额" prop="refund_amount">
       <el-input type="number" v-model="form.refund_amount" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="原因" prop="reason">
        <el-input type="text" v-model="form.reason" placeholder=""></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="submitForClose('ruleForm')" size="small">取消</el-button>
      <el-button @click="submitFormAdd('ruleForm')" type="primary" size="small">确定</el-button>
    </span>
  </el-dialog>
</template>

<script lang="ts">
import { Component, Vue, Prop, Provide } from "vue-property-decorator";

import orderApi from "@/api/order";
@Component({
  components: {}
})
export default class userEditDialog extends Vue {
  // 属性或参数中使用 ！：表示强制解析（告诉typescript编译器，这里一定有值），常用于vue-decorator中的@Prop
  check:boolean = true//防重复提交
  @Prop(Boolean) isRefund!: boolean;
  @Prop(Object) form!: {
    id:number,
    status: string,
    reason:string,
    refund_expect:string,
    refund_amount:number
  };
  @Provide() rules: any = {
    status: [{ required: true, message: "请选择是否通过", trigger: "change" }],
    refund_amount: [{ required: true, message: "请输入退款金额", trigger: "blur" },{
        //pattern: /^[1-9]\d*(\.\d+)?$/,  //大于1
        pattern: /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/,  //正则
        message: '请输入大于0的数'
    }],
    reason: [{ required: true, message: "请输入原因", trigger: "blur" }],
  };
  // 提交deliverGoods
  submitFormAdd(formName: any) {
    (this.$refs[formName] as any).validate((valid: boolean) => {
      if (valid) {
          if(this.form.status=='0'){
            this.form.refund_amount=0
          }
          if(this.check) {
            let _this = this
            _this.check = false
            orderApi.examineOrder(_this.form)
            .then((res: any) => {
              if(res.data.status){
                _this.$message({
                  message: '操作成功',
                  type: "success"
                });
                _this.$emit("closeDialog");
                _this.$emit("loadData")
                setTimeout(function(){
                  _this.check = true
                },3000)
              }else{
                _this.$message({
                  message: res.data.msg,
                  type: "error"
                });
                 _this.check = true
              }
            });
          }
          
      }
    });
  }
  submitForClose(formName: any) {
    (this.$refs[formName] as any).resetFields();
    this.$emit("closeDialog");
  }
  created() {
  }
}
</script>

<style lang="scss" scoped>
.form-box { 
  .el-input,
  .el-select {
    width: 200px !important;
  }
}
</style>
